package com.itheima.test3;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //将本地文件上传到服务器
        //创建Socket对象并指定服务器的IP地址和端口号
        Socket socket = new Socket("127.0.0.1", 8888);
        //获取输出流对象
        BufferedOutputStream bw = new BufferedOutputStream(socket.getOutputStream());
        //读取本地文件并发送给服务器
        BufferedInputStream br = new BufferedInputStream(new FileInputStream("mysocketnet\\Clientdir\\a.jpg"));
        byte[] buffer = new byte[1024];
        int len;
        while ((len= br.read(buffer))!=-1){
            //将读取到的内容发送给服务器
            bw.write(buffer,0,len);
        }
        //关闭输出流，告诉服务器数据已经发送完毕
        socket.shutdownOutput();

        //接收服务器的反馈
        BufferedReader br2=new BufferedReader(new InputStreamReader(socket.getInputStream()));
        System.out.println(br2.readLine());
        //关闭Socket对象
        socket.close();


    }
}
